function [frames,FrameNum,frameRate] = extractFrames(videoFileName,start,finish)
%% Load video frames.
v = VideoReader(videoFileName);%Get video property
v.CurrentTime = start;
frameIdx=0;
frameRate=fix(v.FrameRate);
s = struct('cdata',zeros(v.Height,v.Width,3,'uint8'));
frames = repmat(s,(finish-start+1)*frameRate,1); %Preallocating frames.
while v.CurrentTime<finish
    vidFrame = readFrame(v);
    frameIdx=frameIdx+1;
    frames(frameIdx).cdata=vidFrame;
end
frames=frames(1:frameIdx);
FrameNum=frameIdx;
end

